From: Robert Lipe Date: Sun, 23 Dec 2018 03:51:30 +0000 (-0600) Subject: A moderately uncomfortable series of inadequately tested changes around X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~8^2~51^2 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=039fe53af330715aff807340333c199f8bc18130;p=gpsbabel.git A moderately uncomfortable series of inadequately tested changes around signedness of types, mostly to shut hyperactive tool chains. Time will tell if we fixed or caused more weird cases around trucations and extensions. --- diff --git a/dg-100.cc b/dg-100.cc index 543c8d809..0d93e5f32 100644 --- a/dg-100.cc +++ b/dg-100.cc @@ -632,7 +632,7 @@ dg100_getfiles() dg100_getfileheaders(&headers); - for (int i = 0; i < headers.count; i++) { + for (unsigned int i = 0; i < headers.count; i++) { int filenum = headers.data[i]; dg100_getfile(filenum, &track); } diff --git a/garmin.cc b/garmin.cc index 0757d6e2e..b393706cf 100644 --- a/garmin.cc +++ b/garmin.cc @@ -1133,7 +1133,7 @@ route_write() static void track_hdr_pr(const route_head* trk_head) { - (*cur_tx_tracklist_entry)->ishdr = gpsTrue; + (*cur_tx_tracklist_entry)->ishdr = true; if (!trk_head->rte_name.isEmpty()) { strncpy((*cur_tx_tracklist_entry)->trk_ident, CSTRc(trk_head->rte_name), sizeof((*cur_tx_tracklist_entry)->trk_ident)); (*cur_tx_tracklist_entry)->trk_ident[sizeof((*cur_tx_tracklist_entry)->trk_ident)-1] = 0; diff --git a/jeeps/gps.h b/jeeps/gps.h index b517a901e..c938f99de 100644 --- a/jeeps/gps.h +++ b/jeeps/gps.h @@ -16,9 +16,6 @@ #define MAX_GPS_PACKET_SIZE 1024 #define GPS_TIME_OUT 5 -#define gpsTrue 1 -#define gpsFalse 0 - #define DLE 0x10 #define ETX 0x03 @@ -243,10 +240,10 @@ typedef struct GPS_SCourse_Point { } GPS_OCourse_Point, *GPS_PCourse_Point; typedef struct GPS_SCourse_Limits { - uint32 max_courses; - uint32 max_course_laps; - uint32 max_course_pnt; - uint32 max_course_trk_pnt; + int32 max_courses; + int32 max_course_laps; + int32 max_course_pnt; + int32 max_course_trk_pnt; } GPS_OCourse_Limits, *GPS_PCourse_Limits; diff --git a/jeeps/gpsapp.cc b/jeeps/gpsapp.cc index e1152eab1..6ea16041b 100644 --- a/jeeps/gpsapp.cc +++ b/jeeps/gpsapp.cc @@ -1666,7 +1666,6 @@ static void GPS_D109_Get(GPS_PWay* way, UC* s, int protoid) p += 4; /* Skip over "outbound link ete in seconds */ if (protoid == 110) { float gps_temp; - int gps_time; gps_temp = GPS_Util_Get_Float(p); p+=4; if (gps_temp <= 1.0e24) { @@ -1674,7 +1673,7 @@ static void GPS_D109_Get(GPS_PWay* way, UC* s, int protoid) (*way)->temperature = gps_temp; } - gps_time = GPS_Util_Get_Uint(p); + uint32 gps_time = GPS_Util_Get_Uint(p); p+=4; /* The spec says that 0xffffffff is unknown, but the 60CSX with * firmware 2.5.0 writes zero. diff --git a/jeeps/gpscom.cc b/jeeps/gpscom.cc index 42f3cd1dd..6325732ae 100644 --- a/jeeps/gpscom.cc +++ b/jeeps/gpscom.cc @@ -1247,7 +1247,7 @@ int32 GPS_Command_Send_Track_As_Course(const char* port, GPS_PTrack* trk, int32 cpt = (struct GPS_SCourse_Point**) xrealloc(cpt, (n_cpt+n_wpt) * sizeof(GPS_PCourse_Point)); for (i=0; iRead_Packet)(fd, packet); } -int32 GPS_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) +bool GPS_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) { return (ops->Send_Ack)(fd, tra, rec); } -int32 GPS_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) +bool GPS_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) { return (ops->Get_Ack)(fd, tra, rec); } diff --git a/jeeps/gpsdevice.h b/jeeps/gpsdevice.h index 8d0f30909..7805361cd 100644 --- a/jeeps/gpsdevice.h +++ b/jeeps/gpsdevice.h @@ -38,13 +38,13 @@ int32 GPS_Device_Write(int32 ignored, const void* obuf, int size); void GPS_Device_Error(char* hdr, ...); int32 GPS_Write_Packet(gpsdevh* fd, GPS_PPacket& packet); - int32 GPS_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); + bool GPS_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); int32 GPS_Packet_Read(gpsdevh* fd, GPS_PPacket* packet); - int32 GPS_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); + bool GPS_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); typedef int32(*gps_device_op)(gpsdevh*); typedef int32(*gps_device_op5)(const char*, gpsdevh** fd); - typedef int32(*gps_device_op10)(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); + typedef bool(*gps_device_op10)(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); typedef int32(*gps_device_op12)(gpsdevh* fd, GPS_PPacket& packet); typedef int32(*gps_device_op13)(gpsdevh* fd, GPS_PPacket* packet); typedef struct { diff --git a/jeeps/gpsdevice_usb.cc b/jeeps/gpsdevice_usb.cc index 3471ae0ca..24842b775 100644 --- a/jeeps/gpsdevice_usb.cc +++ b/jeeps/gpsdevice_usb.cc @@ -27,9 +27,9 @@ garmin_unit_info_t garmin_unit_info[GUSB_MAX_UNITS]; -static int32 success_stub() +static bool success_stub() { - return 1; + return true; } static int32 gdu_on(const char* port, gpsdevh** fd) diff --git a/jeeps/gpsread.cc b/jeeps/gpsread.cc index 2ed95e403..e3494b77b 100644 --- a/jeeps/gpsread.cc +++ b/jeeps/gpsread.cc @@ -43,10 +43,10 @@ time_t GPS_Time_Now() { time_t secs; - if (time(&secs)==-1) { + if (time(&secs) < 0) { perror("time"); - GPS_Error("GPS_Time_Now: Error reading time"); gps_errno = HARDWARE_ERROR; + GPS_Error("GPS_Time_Now: Error reading time"); return 0; } @@ -72,24 +72,20 @@ time_t GPS_Time_Now() int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) { time_t start; - int32 len; - UC u; - int32 isDLE; - UC* p; - int32 i; - UC chk=0, chk_read; + int32 len = 0; + UC u; + UC* p; + UC chk = 0, chk_read; const char* m1; const char* m2; - - len = 0; - isDLE = gpsFalse; + bool isDLE = false; p = (*packet).data; start = GPS_Time_Now(); GPS_Diag("Rx Data:"); - while (GPS_Time_Now() < start+GPS_TIME_OUT) { + while (GPS_Time_Now() < start + GPS_TIME_OUT) { if (int32 n = GPS_Serial_Chars_Ready(fd)) { - if (GPS_Serial_Read(fd,&u,1)==-1) { + if (GPS_Serial_Read(fd, &u, 1) < 0) { perror("read"); GPS_Error("GPS_Packet_Read: Read error"); gps_errno = FRAMING_ERROR; @@ -100,7 +96,7 @@ int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) if (!len) { if (u != DLE) { - (void) fprintf(stderr,"GPS_Packet_Read: No DLE. Data received, but probably not a garmin packet.\n"); + (void) fprintf(stderr, "GPS_Packet_Read: No DLE. Data received, but probably not a garmin packet.\n"); (void) fflush(stderr); return 0; } @@ -108,7 +104,7 @@ int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) continue; } - if (len==1) { + if (len == 1) { (*packet).type = u; ++len; continue; @@ -116,10 +112,10 @@ int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) if (u == DLE) { if (isDLE) { - isDLE = gpsFalse; + isDLE = false; continue; } - isDLE = gpsTrue; + isDLE = true; } if (len == 2) { @@ -130,14 +126,15 @@ int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) if (u == ETX) if (isDLE) { - if (p-(*packet).data-2 != (*packet).n) { + if (p - (*packet).data - 2 != (*packet).n) { GPS_Error("GPS_Packet_Read: Bad count"); gps_errno = FRAMING_ERROR; return 0; } - chk_read = *(p-2); + chk_read = *(p - 2); - for (i=0,p=(*packet).data; i<(*packet).n; ++i) { + unsigned int i; + for (i = 0, p = (*packet).data; i < (*packet).n; ++i) { chk -= *p++; } chk -= packet->type; @@ -151,9 +148,9 @@ int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) m1 = Get_Pkt_Type((*packet).type, (*packet).data[0], &m2); if (gps_show_bytes) { GPS_Diag(" "); - for (i = 0; i < packet->n; i++) { + for (unsigned i = 0; i < packet->n; i++) { char c = (*packet).data[i]; - GPS_Diag("%c", isalnum(c) ? c : '.'); + GPS_Diag("%c", isalnum(c) ? c : '.'); } GPS_Diag(" "); } @@ -187,13 +184,13 @@ int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) ** @param [r] tra [GPS_PPacket *] packet just transmitted ** @param [r] rec [GPS_PPacket *] packet to receive ** -** @return [int32] true if ACK +** @return [bool] true if ACK **********************************************************************/ -int32 GPS_Serial_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) +bool GPS_Serial_Get_Ack(gpsdevh *fd, GPS_PPacket *tra, GPS_PPacket *rec) { if (!GPS_Serial_Packet_Read(fd, rec)) { - return 0; + return false; } if (LINK_ID[0].Pid_Ack_Byte != (*rec).type) { @@ -203,8 +200,8 @@ int32 GPS_Serial_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) if (*(*rec).data != (*tra).type) { gps_error = FRAMING_ERROR; - return 0; + return false; } - return 1; + return true; } diff --git a/jeeps/gpsread.h b/jeeps/gpsread.h index fa1c501bb..07f61d0c1 100644 --- a/jeeps/gpsread.h +++ b/jeeps/gpsread.h @@ -6,6 +6,6 @@ time_t GPS_Time_Now(); int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet); - int32 GPS_Serial_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); + bool GPS_Serial_Get_Ack(gpsdevh *fd, GPS_PPacket *tra, GPS_PPacket *rec); #endif diff --git a/jeeps/gpssend.cc b/jeeps/gpssend.cc index 52e0b3910..04b5fdc10 100644 --- a/jeeps/gpssend.cc +++ b/jeeps/gpssend.cc @@ -44,10 +44,8 @@ Build_Serial_Packet(GPS_PPacket in, GPS_Serial_PPacket out) { UC* p; UC* q; - - int32 i; - UC chk=0; - US bytes=0; + UC chk = 0; + US bytes = 0; p = in.data; q = out->data; @@ -67,7 +65,7 @@ Build_Serial_Packet(GPS_PPacket in, GPS_Serial_PPacket out) chk -= in.n; - for (i = 0; i < in.n; ++i) { + for (uint32 i = 0; i < in.n; ++i) { if (*p == DLE) { ++bytes; *q++ = DLE; @@ -188,10 +186,10 @@ int32 GPS_Serial_Write_Packet(gpsdevh* fd, GPS_PPacket& packet) ** @param [r] tra [GPS_PPacket *] packet to transmit ** @param [r] rec [GPS_PPacket *] last packet received ** -** @return [int32] success +** @return [bool] success ************************************************************************/ -int32 GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) +bool GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) { UC data[2]; @@ -200,8 +198,8 @@ int32 GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) if (!GPS_Write_Packet(fd,*tra)) { GPS_Error("Error acknowledging packet"); gps_errno = SERIAL_ERROR; - return 0; + return false; } - return 1; + return true; } diff --git a/jeeps/gpssend.h b/jeeps/gpssend.h index 4be5dfa38..870991138 100644 --- a/jeeps/gpssend.h +++ b/jeeps/gpssend.h @@ -7,7 +7,7 @@ #define GPS_ARB_LEN 1024 int32 GPS_Serial_Write_Packet(gpsdevh* fd, GPS_PPacket& packet); - int32 GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); + bool GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); void GPS_Make_Packet(GPS_PPacket* packet, US type, UC* data, uint32 n); diff --git a/navilink.cc b/navilink.cc index f2542225c..0a39c9a57 100644 --- a/navilink.cc +++ b/navilink.cc @@ -290,17 +290,15 @@ read_word() */ static bool read_packet(unsigned type, void* payload, - unsigned minlength, unsigned maxlength, + int minlength, int maxlength, bool handle_nak) { - unsigned size; - unsigned checksum; - if (read_word() != 0xa2a0) { fatal(MYNAME ": Protocol error: Bad packet header." " Is your NaviGPS in NAVILINK mode?\n"); } + int size; if ((size = read_word()) <= minlength) { fatal(MYNAME ": Protocol error: Packet too short\n"); } @@ -323,6 +321,7 @@ read_packet(unsigned type, void* payload, fatal(MYNAME ": Protocol error: Bad packet type (expected 0x%02x but got 0x%02x)\n", type, data[0]); } + unsigned checksum; if ((checksum = read_word()) != navilink_checksum_packet(data, size)) { fatal(MYNAME ": Checksum error - expected %x got %x\n", navilink_checksum_packet(data, size), checksum); diff --git a/skytraq.cc b/skytraq.cc index a178a5d93..327b45a4b 100644 --- a/skytraq.cc +++ b/skytraq.cc @@ -273,7 +273,7 @@ skytraq_rd_msg(const void* payload, unsigned int len) { int errors = 5; /* allow this many errors */ unsigned int c, i, state; - signed int rcv_len; + unsigned int rcv_len; for (i = 0, state = 0; i < RETRIES && state < sizeof(MSG_START); i++) { c = rd_char(&errors);